package com.qf.controller;

import com.qf.pojo.DtsGroupon;
import com.qf.pojo.DtsGrouponRules;
import com.qf.service.DtsGoodsService;
import com.qf.service.DtsGrouponRulesService;
import com.qf.service.DtsGrouponService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/groupon")
public class AdminGrouponController {
    @Autowired
    DtsGrouponService grouponService;
    @Autowired
    DtsGrouponRulesService grouponRulesService;
    @Autowired
    DtsGoodsService goodsService;
    @PostMapping("/delete")
    public Object delete(@RequestBody DtsGrouponRules grouponRules) {
        grouponRulesService.delete(grouponRules);
        return ResponseUtil.ok();
    }
    @PostMapping("/update")
    public Object update(@RequestBody DtsGrouponRules grouponRules) {
        DtsGrouponRules data = grouponRulesService.update(grouponRules);
        return ResponseUtil.ok(data);
    }
    @PostMapping("/create")
    public Object create(@RequestBody DtsGrouponRules grouponRules) {
        DtsGrouponRules data = grouponRulesService.create(grouponRules);
        return ResponseUtil.ok(data);
    }
    @GetMapping("/list")
    public Object groupon(
            @RequestParam(value = "page",required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit",required = false, defaultValue = "20")Integer limit,
            Integer goodsId,String sort,String order
    ){
        Map<String,Object> data = grouponRulesService.queryIpage(page,limit,goodsId,sort,order);
        return ResponseUtil.ok(data);
    }
}